from django.shortcuts import render
from paper.models import Category


# Create your views here.

def index(request):
    return render(request, template_name="hello.html")


def category_list(request):
    categories = Category.objects.filter(parent=None)  # 获取所有一级分类
    return render(request, 'category_list.html', {'categories': categories})


def subcategory_list(request, parent_id):
    parent_category = Category.objects.get(id=parent_id)
    subcategories = Category.objects.filter(parent=parent_category)  # 获取所有二级分类
    return render(request, 'subcategory_list.html',
                  {'parent_category': parent_category, 'subcategories': subcategories})
